using System.Collections.Generic;

namespace IQIGame.Onigao.GamePlay
{
    public class DynParamProcessSwitchState : DynParamProcessBase
    {
        public DynParamProcessSwitchState(LevelPlayRegionController regionCtrl) : base(regionCtrl)
        {
        }

        public override EntityDynamicParamType paramType => EntityDynamicParamType.EntitySwitchState;

        public override bool isContainTriggerRect => true;

        public override void OnEntityAddProcess(LevelPlayBaseEntity entity, BaseEntityDynamicParam currentParam, in IReadOnlyDictionary<EntityDynamicParamType, BaseEntityDynamicParam> paramMap)
        {
            var param = currentParam as EntityParamSwitchState;
            if (param == null)
            {
                return;
            }
            var component = entity.AddComponentWithPool<LevelSimpleStateComponent>(ETComponentType.LevelSimpleState, out var isCreate);
            if (isCreate)
            {
                component.InitSimpleStateEntity(param);
            }
            base.OnEntityAddProcess(entity, currentParam, paramMap);
        }

        public override void OnOneParamEffectiveAdded(BaseEntityDynamicParam paramValue, LevelPlayBaseEntity entity)
        {
            var stateComponnt = entity.GetLevelSimpleStateComponent();
            MsgDispatcher.Broadcast<LevelPlayBaseEntity, EntityParamSwitchState, int>(MsgEventType.Level_EntityStateChanged, entity, stateComponnt.switchState, stateComponnt.currentStateIndex);
        }

    }

}
